#ifndef __LUOO_CSV_RECORD_HPP__
#define __LUOO_CSV_RECORD_HPP__

#include <vector>
#include <string>
#include <sstream>

namespace luoo
{
	typedef enum csv_trash_type { trash };

	class csv_record
	{
	private:
		typedef std::vector<std::string> record;

	public:
		csv_record()
			: nonius_(0)
		{}

		void clear()
		{
			record_.clear();
		}

		void push(std::string& value)
		{
			record_.push_back(value);
		}

		size_t size()
		{
			return record_.size();
		}

		csv_record& operator >> (csv_trash_type)
		{
			if (nonius_ < record_.size())
			{
				nonius_++;
			}

			return *this;
		}
	
		template<typename T>
		csv_record& operator >> (T& value)
		{
			if (nonius_ < record_.size())
			{
				std::stringstream ss;
				ss << record_[nonius_++];
				ss >> value;
			}

			return *this;
		}

		csv_record& operator >> (std::string& value)
		{
			if (nonius_ < record_.size())
			{
				value = record_[nonius_++];
			}

			return *this;
		}

		csv_record& operator >> (char*& value)
		{
			if (NULL != value)
			{
				memcpy(value, record_[nonius_++].c_str(), record_.size());
			}

			return *this;
		}

		csv_record& operator >> (const char*& value)
		{
			if (nonius_ < record_.size())
			{
				value = record_[nonius_++].c_str();
			}

			return *this;
		}

	private:
		size_t nonius_;
		record record_;
	};
}// namespace luoo

#endif//__LUOO_CSV_RECORD_HPP__